package com.example.database_manage.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBOpenHelper extends SQLiteOpenHelper {


    public DBOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        //学生
        String sql_student = "create table student(" +
                "id int primary key not null ," +
                "name varchar(20) not null," +
                "sex varchar(10) not null," +
                "age int check(age<100 and age>0)," +
                "banji varchar(20) ," +
                "college varchar(20) default '无') ";


        db.execSQL(sql_student);

        //管理员表
        String sql_admin = "create table administractor(" +
                " account varchar(20)," +
                " password varchar(20))";

        String sql_insert_admin1 = "insert into administractor values('MWQ','6f3883c2533e7898c39e454b368405f9')";

        db.execSQL(sql_admin);
        db.execSQL(sql_insert_admin1);


        //测试数据
        String sql_p = "insert into student(id ,name ,sex,age ,banji ,  college )" +
                " values(2018171203,'马冬梅','女',19,'物联网班','计算机与信息学院')";
        String sql_p1 = "insert into student(id ,name ,sex,age ,banji , college )" +
                " values(2018171229,'任晓晓','女',20,'物联网班','计算机与信息学院')";
        String sql_p2 = "insert into student(id ,name ,sex,age ,banji , college )" +
                " values(2018111233,'郑露露','男',19,'金融班','经济与管理学院')";
        String sql_p3 = "insert into student(id ,name ,sex,age ,banji , college )" +
                " values(2018132229,'方静静','男',20,'韩语班','外国语学院')";
        String sql_p4 = "insert into student(id ,name ,sex,age ,banji ,  college )" +
                " values(2018110211,'张心台','男',20,'金属材料班班','材料与化工学院')";
        String sql_p5 = "insert into student(id ,name ,sex,age ,banji ,  college )" +
                " values(20181512027,'王冰冰','女',20,'美术班','艺术学院')";
        String sql_p6 = "insert into student(id ,name ,sex,age ,banji ,  college )" +
                " values(2018171244,'蔡小洪','男',20,'物联网班','计算机与信息学院')";
        String sql_p7 = "insert into student(id ,name ,sex,age ,banji ,  college )" +
                " values(20181512055,'钟蕾','女',19,'物联网班','计算机与信息学院')";
        String sql_p8 = "insert into student(id ,name ,sex,age ,banji ,  college )" +
                " values(20181512066,'何小冰','女',20,'物联网班','计算机与信息学院')";


        db.execSQL(sql_p);
        db.execSQL(sql_p1);
        db.execSQL(sql_p2);
        db.execSQL(sql_p3);
        db.execSQL(sql_p4);
        db.execSQL(sql_p5);
        db.execSQL(sql_p6);
        db.execSQL(sql_p7);
        db.execSQL(sql_p8);



    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}
